package class06;

/**
 * @Auther: xw
 * @Create: 2022/3/25 15:52
 * @Description: 测试链接：https://leetcode.com/problems/symmetric-tree  判断一棵树是否是镜像树
 */
public class SymmetricTree {

    public static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;
    }

    public static boolean isSymmetric(TreeNode root){
        return isMirror(root,root);
    }

    public static boolean isMirror(TreeNode h1,TreeNode h2){
        if(h1 == null ^ h2 == null){
            return false;
        }
        if(h1== null && h2 == null){
            return true;
        }

        return h1.val == h2.val && isMirror(h1.left,h2.right) && isMirror(h1.right,h2.left);
    }
}
